<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>配置管理</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0"> 
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<jsp:include page="../resource.jsp"></jsp:include> 
<style type="text/css">
  .loadingImg {
	background: url('../images/loading1.gif');
	height:60px;
	width:60px;
	background-repeat: no-repeat;
	margin-left:250px;  
    margin-top : 200px;
  }
</style>
<script type="text/javascript">
$(document).ready(function() {
	
	var $el = $('<div></div>').addClass('om-widget-overlay') //蒙版
				.css({
					width: $(window).width(),
					height: $(window).height()
				}).append($('<div></div>').addClass('loadingImg'));
	
      	$('#deviceTree').omTree({
      		dataSource : 'reOrDeTe!queryAll.do',
            widht : 700,
            showCheckbox : true,
            onBeforeExpand : function(node){
            	$el.appendTo(document.body);
            	var nodeDom = $("#"+node.nid);
            	if(nodeDom.hasClass("hasChildren") && nodeDom.children("ul").children().length == 0){
            		nodeDom.removeClass("hasChildren");
            		$.ajax({
                        url: 'reOrDeTe!queryAll.do?queryId='+node.id,
                        method: 'POST',
                        dataType: 'json',
                        success: function(data){
                            $("#deviceTree").omTree("insert", data, node);
                            $el.remove();
                        }
                    });
            	}else{
            		$el.remove();
            	}
            	return true;
            },
            onClick:function(){
            	$('#root').parent().removeClass('selected');
            },
            onCheck: function(nodeData){
            	var checked = $('#deviceTree').omTree('getChecked',true);
            	var ids = '';
            	for(var i=0 ;i<checked.length ; i++){
            		if(checked[i].id.indexOf('te_') == -1){ //终端不计算在内
	            		ids +=checked[i].id+',';
            		}
            	}
            	$('#deviceIds').val(ids);
			}
      	});
      	
      	 $('#root').click(function(){
	   		  $(this).parent().addClass('selected');
	   		  $('#deviceTree').find('span.selected').removeClass('selected');
	   	  });
      	
      	 $('#deviceregions').omCombo({
             dataSource : 'reOrDeTe!findRegions.do',
             onValueChange : function(target, newValue, oldValue) {
                 getOrganizationRecords();
             }
         });
      	$('#deviceregions').bind('change',function(){
      	    if($('#deviceregions').val() == ''){
      	    	$('#deviceregions').omCombo('value','');
      	    }
      	})
      	 
      	 $('#deviceorganization').omCombo({
             dataSource : 'reOrDeTe!findOrganizations.do',
             onValueChange : function(target, newValue, oldValue) {
                 getDevice();
                 if($('#deviceorganization').val() == ''){
                	 $('#deviceorganization').omCombo('value','');
                 }
             }
         });
      	$('#deviceorganization').bind('change',function(){
      	    if($('#deviceorganization').val() == ''){
      	    	$('#deviceorganization').omCombo('value','');
      	    }
      	})
      	 $('#devicedevice').omCombo({
             dataSource : 'reOrDeTe!findDevices.do',
             onValueChange : function(target, newValue, oldValue) {
                 getDevice();
             }
         });
      	$('#devicedevice').bind('change',function(){
      	    if($('#devicedevice').val() == ''){
      	    	$('#devicedevice').omCombo('value','');
      	    }
      	})
      	 function getOrganizationRecords(){
      		var regions = $('#deviceregions').omCombo('value');
            $.ajax({
            	url : 'reOrDeTe!findOrganizations.do',
                data : {regionsId : regions},
                dataType : 'json',
                async : false,
                success : function(data){
                	$('#deviceorganization').val('').omCombo('setData', data);
                	$('#devicedevice').val('').omCombo( 'setData', []);
                	$('#deviceorganization').omCombo('value','');
                	$('#devicedevice').omCombo('value','');
                }
            });
      	 }
      	 
      	 function getDevice(){
      		var organization = $('#deviceorganization').omCombo('value');
            $.ajax({
            	url : 'reOrDeTe!findDevices.do',
                data : {organizationId : organization},
                dataType : 'json',
                async : false,
                success : function(data){
                	$('#devicedevice').val('').omCombo('setData', data);
                }
            });
      	 }
      	 
      	 $('#deviceserachTree').click(function(){
      		$el.appendTo(document.body);
      		var regions = $('#deviceregions').omCombo('value');
      		var organization = $('#deviceorganization').omCombo('value');
      		var device = $('#devicedevice').omCombo('value');
      		if(device){
      			queryTreeData('de_'+device);
      		}else if(organization){
      			queryTreeData('or_'+organization);
      		}else if(regions){
      			queryTreeData('re_'+regions);
      		}else{
      			queryTreeData(null);
      		}
      	 });
      	 
      	 function queryTreeData(id){
      		$('#deviceTree').omTree('setData' , 'reOrDeTe!queryAll.do?queryId='+id);
			$('#deviceTree').omTree('refresh');
			$el.remove();
      	 }
      	 
      	$("#deviceParamsEditor").omDialog({
        	autoOpen: false,
  		    height: 550,
  		    width : 480,
  		    modal: true,
  		    buttons: [{
                text : "确定", 
                click : function () {
                  $("#deviceParamsForm").submit();
                }
             }, {
                text : "取消", 
                click : function () {
                  $("#deviceParamsEditor" ).omDialog("close");
              }
          }]
        });
      	
      	$('#paramsSetting').click(function(){
      		$('#deviceParamsForm').resetForm();
      		var selects = $("#deviceIds").val(); //如果选择两个以上的记录，则为批量设置，不会读取出记录
      		var ida = selects?selects.split(','):null;
        	if(ida && ida.length > 2){ //批量设置
        		$("#deviceParamsEditor").omDialog('open');
        	}else if(ida && ida.length == 2 && ida[1] == ''){ //单个设置，如果有记录先读取
        		$.ajax({
        			url : 'paramServer!findByDeviceId.do',
        			data : {deviceId : ida[0]},
        			dataType : 'json',
        			success : function(data){
        				if(data){
	        				$('#paramsIp').val(data.ip);
	        				$('#terminalCount').val(data.terminalCount);
	        				$('#portCtrl').val(data.portCtrl);
	        				$('#portData').val(data.portData);
	        				$('#portFtp').val(data.portFtp);
	        				$('#portHttp').val(data.portHttp);
	        				$('#managerServerIp').val(data.managerServerIp);
	        				$('#managerServerUser').val(data.managerServerUser);
	        				$('#managerServerPwd').val(data.managerServerPwd);
	        				$('#backupServerIp').val(data.backupServerIp);
	        				$('#hasAudio').val(data.hasAudio);
	        				$('#comParam').val(data.comParam);
        				}
        				$("#deviceParamsEditor").omDialog('open');
        			}
        		});
        	}
      	});
      	
   	  $('#deviceParamsForm').submit(function() {
             $(this).omAjaxSubmit({
             	url : 'paramServer!saveParamserver.do',
       		    data: { deviceIds: $('#deviceIds').val()},
                 success : function(data){
                    	if(data == '1'){ 
                        	$('#deviceParamsEditor').omDialog('close');
                        	$.omMessageTip.show({timeout : 2000,content : '保存成功！'});
                    	}else{
                    		$.omMessageTip.show({timeout : 2000,content : '保存失败！',type : 'error'});
                    	}
                 }});
             return false;//返回false,阻止浏览器默认行为
         });

      $('#jobMode').omCombo({
      		dataSource : 'upgrade!findJobMode.do',
          onValueChange : function(target, newValue, oldValue) {
          	 $('#jobModeId').val(newValue);
          }
      });
      if($('#serverJobStartTime').next().attr('class') != 'om-calendar-trigger') {
 		 $('#serverJobStartTime').omCalendar({showTime : true});
 	  }
});

</script>   
  </head>
  
  <body>
  <div class="select_table">


<table   cellpadding="0" cellspacing="0" class="layout"  >

          <tr>
            <td width="5%" align="right">区域：</td>
            <td width="12%">
              <input name="regions" id="deviceregions" type="text"/>
            </div></td>
            <td width="5%" align="right">组织：</td>
            <td width="12%">
              <input name="organization" id="deviceorganization" type="text"/>
            </div></td>
            <td width="5%" align="right">设备：</td>
            <td width="12%">
              <input name="device" id="devicedevice" type="text"/>
            </div></td>
            <td>
            <td align="left">
            <button class="button_u" id="deviceserachTree" onmousemove="this.className='button_f'" onmousedown="this.className='button_d'" onmouseout="this.className='button_u'">查询</button></td>
            </td>
          </td>
          </tr>
          </table>
</div>
    <div class="toolbar mar">
      <a href="#" class="rbutton" id="paramsSetting"><span><img src="../images/add.gif" width="14" height="14" /><ins>参数设置</ins></span></a>
	  <a  class="line"></A>
    </div>
	<div class="catalogTree">
     <ul class="om-tree om-widget">
	     <li class="om-tree-node collapsable">
	        <div class="hitarea om-tree-node-hitarea -hitarea collapsable-hitarea"></div>
	        <span class="folder selected"><a href="#" id="root">设备菜单</a></span>
	        <ul id="deviceTree"></ul>
	     </li>
	 </ul>
	</div>
	
	<div id="deviceParamsEditor" title="设置设备参数" style="display: none;">
	 <input type="hidden" id="deviceIds" name="deviceIds"> <!-- 选中的设备id,以逗号分隔 -->
     <form id="deviceParamsForm" method="post">
          <table width="100%" border="0" class="grid_layout" cellspacing="0">
             <tr>
               <td width="14%" align="right">IP地址：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="pars.ip" id="paramsIp" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">挂接终端数量：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="pars.terminalCount" id="terminalCount" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">信令端口：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="pars.portCtrl" id="portCtrl" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">控制端口号：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="pars.portData" id="portData" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">ftp端口号：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="pars.portFtp" id="portFtp" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">http端口号：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="pars.portHttp" id="portHttp" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">拥有者ip地址：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="pars.managerServerIp" id="managerServerIp" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">上级平台用户帐号：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="pars.managerServerUser" id="managerServerUser" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">上级平台用户密码：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="pars.managerServerPwd" id="managerServerPwd" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">备份平台服务器ip地址：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="pars.backupServerIp" id="backupServerIp" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="14%" align="right">串口参数：</td>
               <td width="28%" colspan="3" align="left">
               	<input type="text" name="pars.comParam" id="comParam" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="20%" align="right">开始时间：</td>
               <td width="68%" colspan="3">
                  <input type="text" id="serverJobStartTime" name="serverToDevice.startTime">
               </td>
             </tr>
             <tr>
               <td width="20%" align="right">任务执行方式：</td>
               <td width="68%" colspan="3">
                  <input id="jobMode" name="jobMode">
                  <input id="jobModeId" name="jobModeId" type="hidden">
               </td>
             </tr>
           </table>
         </form>
   </div>
  </body>
</html>
